package com.splant.android.smart.UILevel.Community.fragments;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.splant.android.R;
import com.splant.android.smart.Global;
import com.splant.android.smart.UILevel.Community.Garden_AboutUs_Activity;
import com.splant.android.smart.UILevel.Community.Garden_Login_Activity;
import com.splant.android.smart.UILevel.Community.Garden_MessageList_Activity;
import com.splant.android.smart.UILevel.Community.Garden_UpdatePsw_Activity;
import com.tencent.mm.opensdk.modelbiz.JumpToBizProfile;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import de.hdodenhof.circleimageview.CircleImageView;
/**
 * Created by Administrator on 2017/6/21.
 */

public class Garden_Me_Fragment extends Fragment implements View.OnClickListener {

    private RelativeLayout rl_updatePsw;
    private RelativeLayout rl_msg;
 //   private RelativeLayout rl_splantby;
    private RelativeLayout rl_about;
    private RelativeLayout rl_logout;

    private CircleImageView cImg_logo;
    private TextView tv_address;
    private TextView tv_userName;
    private TextView tv_companyName;
    private View mView;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (mView == null) {
            mView = inflater.inflate(R.layout.garden_me_fragment,null);

            rl_updatePsw= (RelativeLayout) mView.findViewById(R.id.rl_updatePsw);
            rl_msg= (RelativeLayout) mView.findViewById(R.id.rl_msg);
           // rl_splantby= (RelativeLayout) mView.findViewById(R.id.rl_splantby);
            rl_about= (RelativeLayout) mView.findViewById(R.id.rl_about);
            rl_logout= (RelativeLayout) mView.findViewById(R.id.rl_logout);
            cImg_logo= (CircleImageView) mView.findViewById(R.id.cImg_logo);
            tv_address= (TextView) mView.findViewById(R.id.tv_address);
            tv_userName= (TextView) mView.findViewById(R.id.tv_userName);
            tv_companyName= (TextView) mView.findViewById(R.id.tv_companyName);

            init();

            rl_updatePsw.setOnClickListener(this);
            rl_msg.setOnClickListener(this);
           // rl_splantby.setOnClickListener(this);
            rl_about.setOnClickListener(this);
            rl_logout.setOnClickListener(this);
        }
        return mView;
    }
    private static final String APP_ID="wx9ad7b3de454d7615";
    private IWXAPI iwxapi;
    private void regToWx()
    {
        iwxapi= WXAPIFactory.createWXAPI(getActivity(),APP_ID,false);
        iwxapi.registerApp(APP_ID);
    }

    private void init()
    {
        if (Global.user!=null)
        {
            Glide.with(getActivity())
                    .load(Global.user.getLogoUrl())
                    .dontAnimate()
                    .placeholder(R.mipmap.garden_ic_plantimg_fail)
                    .into(cImg_logo);

            tv_address.setText(Global.user.getCompanyAddress());
            tv_userName.setText(Global.user.getUserName());
            tv_companyName.setText(Global.user.getCompanyName());

            regToWx();
        }
    }

    @Override
    public void onClick(View v) {

        switch (v.getId())
        {
            case R.id.rl_updatePsw:

                Intent updatePsw=new Intent(getActivity(), Garden_UpdatePsw_Activity.class);
                startActivity(updatePsw);

                break;
            case R.id.rl_msg:
                Intent messageListIntent=new Intent(getActivity(), Garden_MessageList_Activity.class);
                startActivity(messageListIntent);
                break;
//            case R.id.rl_splantby:
//
//                if (iwxapi.isWXAppInstalled())
//                {
//                    JumpToBizProfile.Req req = new JumpToBizProfile.Req();
//                    req.toUserName = "gh_703dbb9c3fff"; //公众号原始ID
//                    req.profileType = JumpToBizProfile.JUMP_TO_NORMAL_BIZ_PROFILE;
//                    req.extMsg = "森保养";
//                    iwxapi.sendReq(req);
//                }
//                else
//                    Toast.makeText(getActivity(), "微信未安装", Toast.LENGTH_SHORT).show();
//
//                break;
            case R.id.rl_about:
                Intent intent2=new Intent(getActivity(), Garden_AboutUs_Activity.class);
                startActivity(intent2);
                break;
            case R.id.rl_logout:
                Intent intent=new Intent(getActivity(), Garden_Login_Activity.class);
                startActivity(intent);
                getActivity().finish();
                break;
        }
    }
}
